package com.douya.mvc.config;


import com.douya.mvc.intercetor.LoggingInterceptor;
import com.douya.mvc.service.HttpLoggingService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

/**
 * http日志配置
 *
 * @Author hcy
 * @Date 2024/4/2  15:26
 */
@Configuration
@ConditionalOnProperty(name = "douya.mvc.enable-http-logger", matchIfMissing = true, havingValue = "true")
public class HttpLoggingConfig implements WebMvcConfigurer {
    @Resource
    HttpLoggingService httpLoggingService;

    @Value("${spring.application.name}")
    String applicationName;

    /**
     * 日志拦截器
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(
                new LoggingInterceptor(httpLoggingService, applicationName)
        ).addPathPatterns("/**");
    }
}
